package com.goldplusgold.network.lib.http.netty;

import java.util.concurrent.TimeUnit;

import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelFutureListener;
import io.netty.channel.EventLoop;

/**
 * Created by Administrator on 2017/5/3.
 */

public class ConnectionListener<T extends ChannelBootstrapImpl> implements ChannelFutureListener {
    private T client;

    public ConnectionListener(T client) {
        this.client = client;
    }

    @Override
    public void operationComplete(ChannelFuture future) throws Exception {
        if (!future.isSuccess()) {
            System.out.println("Reconnection");
            final EventLoop eventLoop = future.channel().eventLoop();
            eventLoop.schedule(new Runnable() {
                @Override
                public void run() {
                    client.start();
                }
            }, 1L, TimeUnit.SECONDS);
        }
    }
}
